package com.situ.mall.thread;


import com.situ.mall.lambda.MyRunnable;
import com.situ.mall.pojp.Student;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;

public class ThreadTest {
    public static void main(String[] args) {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable, "myRunnable");
        thread.start();

        //匿名内部类 只用一次的
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {

            }
        });
        thread.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ThreadTest.run");
            }
        }).start();

        new Thread(() -> System.out.println("ThreadTest")).start();

        /*Lambda的标准格式：

        (参数列表) -> {
            方法体
        }
        1、(参数列表)：参数列表
        2、{}：方法体
        3、->：没有实际含义，起到连接的作用
        组成Lambda表达式的三要素：形式参数，箭头，代码块*/
        new Thread(() -> {
            System.out.println("ThreadTest.main");
        }).start();
        new Thread(() -> System.out.println("ThreadTest.main")).start();

    }

    @Test
    public void test1(){
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(5,"张三",34));
        list.add(new Student(8, "李四", 45));
        list.add(new Student(6, "王五", 87));
        list.add(new Student(2, "赵六", 22));
        /*Collections.sort(list, new Comparator<Student>() {          sort方法，new一个Comparator接口
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });*/
        /*Collections.sort(list, (Student o1, Student o2) -> {
            return o1.getAge() - o2.getAge();
        });*/
//
        Collections.sort(list, (o1, o2) -> o1.getAge() - o2.getAge());
        for (Student student : list) {
            System.out.println(student);
    }
        System.out.println("------------------------------------------------");
        Collections.sort(list,((o1, o2) -> o2.getId() - o1.getId()));
        for (Student student1 : list) {
            System.out.println(student1);
        }
    }
}
